package com.mars.foodserver.controller.common;

import com.mars.foodserver.utils.JwtUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wq
 * @version 1.0
 * @date 2021/07/27 17:55
 */
public class BaseController {

    private HttpServletRequest request;

    @ModelAttribute
    void setRequest(HttpServletRequest request) {
        this.request = request;
    }


    public Integer getUserId() {
        String userId = JwtUtil.getUserId(request.getHeader("token"));
        if (StringUtils.isNotEmpty(userId)) {
            return Integer.parseInt(userId);
        }
        return null;
    }
}
